<template>
  <div class="main">
    <el-card>
      <template #header>用户注册</template>

      <div>
        <el-form>
          <el-form-item>
            <el-input v-model="user.username" placeholder="登录名"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input
              show-password
              v-model="user.password"
              placeholder="登录密码"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>

      <template #footer>
        <el-button @click="reg" type="primary">
          <el-icon style="margin-right: 0.3rem"><Plus /></el-icon>
          注册</el-button
        >
        <el-button @click="login" type="success">
          <el-icon style="margin-right: 0.3rem"><Back /></el-icon>
          返回登录</el-button
        >
      </template>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { api } from '../../js/ajax'
import { tools } from '../../js/tools'
import { ElMessageBox } from 'element-plus'
import { useRouter } from 'vue-router'

const router = useRouter()

const user = ref({
  username: '',
  password: '',
})

const loading = ref(false)

const reg = () => {
  loading.value = true
  api.post('/user', user.value, data => {
    loading.value = false
    ElMessageBox.alert(data.message, '注册用户')
  })
}
const login = () => {
  router.push('/user/login')
}
</script>

<style scoped>
.main {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
